package com.xunfang.controller;

import com.github.pagehelper.PageInfo;
import com.xunfang.bean.Building;
import com.xunfang.bean.Result;
import com.xunfang.service.BuildingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yellow Doctor
 * @date 2025-09-12
 * @desc https://blog.csdn.net/hekai7217
 */
@RestController
@Tag(name = "build楼栋管理模块")  //当前的类的作用    name文字说明
@RequestMapping("building")
public class BuildController {

    @Autowired
    private BuildingService buildingService;

    //初始化日志
    private static Logger logger =  LoggerFactory.getLogger(BuildController.class);


    // @GetMapping("/list/{-3}/中彩票")
    // 直接返回 集合
    @Operation(summary = "查询所有")   //方法说明
    @GetMapping("/list/{currentPage}/{pageSize}")
    public Result<PageInfo> selectAllBuild(@PathVariable("currentPage") Integer currentPage,
                                           @PathVariable("pageSize") Integer pageSize){
        return buildingService.selectAllBuilding(currentPage,pageSize);
    }


    @Operation(summary = "添加数据")
    @PostMapping("")
    public Result addBuild(@RequestBody Building building){
        return buildingService.addBuild(building);
    }

    //building/56
    @Operation(summary = "通过id删除数据")
    @DeleteMapping("/{id}")
    public Result addBuild(@PathVariable("id") int id){
        return buildingService.deleteBuild(id);
    }

    //url http://localhost:8080/building
    //参数     [1, 2]
    @DeleteMapping("")
    public Result batchBuild(@RequestBody List<Integer> ids){
        return buildingService.batchBuild(ids);
    }

    @PutMapping("")
    public Result updateBuild(@RequestBody Building building){
        return buildingService.updateBuild(building);
    }

    @GetMapping("/logger")
    public String logger(){
        //可以自动开启 关闭进行配置
        logger.info("====================日志打印输出===================");
        return "打印日志";
    }

}
